package com.bdy.lm.taximanager.ui;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.bdy.lm.taximanager.R;
import com.bdy.lm.taximanager.app.MyApp;
import com.bdy.lm.taximanager.model.SerialPortData;

import java.util.Timer;
import java.util.TimerTask;

public class EvaluateActivity extends Activity {

    private TextView thankEvaluate;
    private String evaluate  = "null";
    public static final String EVALUATE_RESULT = "evaluateResult";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //请求窗口的标题 为无标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //要求窗口全屏显示
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_evaluate);
        thankEvaluate = (TextView) findViewById(R.id.thank_evaluate);
        this.setResult(RESULT_OK);
        //若10秒之内没有评价则退出
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                SerialPortData.getInstance().getTransitionData().setEvaluate(evaluate);
                MyApp.transitionNum = SerialPortData.getInstance().getTransitionData().getCurrentRunTime();
                finish();
            }
        }, 10000);
    }

    public boolean onKeyDown(int i, KeyEvent k) {
        if (i == 16) {
            evaluate = "satisfaction";
        } else if (i == 15) {
            evaluate = "ordinary";
        } else if (i == 14) {
            evaluate = "dissatisfaction";
        }
        SerialPortData.getInstance().getTransitionData().setEvaluate(evaluate);
        Log.d("EvaluateActivity", SerialPortData.getInstance().getTransitionData().toString());
        MyApp.transitionNum = SerialPortData.getInstance().getTransitionData().getCurrentRunTime();
        thankEvaluate.setText("感谢您的评价！");
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                finish();
            }
        }, 1000);
        return true;
    }
}
